package com.easemob.chat;

import com.easemob.util.EMLog;

class EMSDKLocalTest
{
  static long previousMsgTime = 0L;

  public static void addMsgs(String paramString, int paramInt)
  {
    EMLog.d("db", "start to add test message to:" + paramString + " msgs:" + paramInt);
    long l = System.currentTimeMillis();
    for (int i = 0; i < paramInt; i++)
    {
      EMMessage localEMMessage;
      if (i % 2 == 0)
        localEMMessage = createSentTextMsg(paramString);
      else
        localEMMessage = createReceivedTextMsg(paramString);
      EMChatDB.getInstance().importMessage(localEMMessage);
    }
    EMLog.d("db", "finished add test data. time spend:" + (System.currentTimeMillis() - l) / 1000L);
  }

  public static void addConversations(int paramInt1, int paramInt2)
  {
    EMLog.d("db", "[perf] start to add test conversations:" + paramInt1 + " msg:" + paramInt2);
    long l = System.currentTimeMillis();
    for (int i = 1; i <= paramInt1; i++)
    {
      String str = "user" + i;
      addMsgs(str, paramInt2);
    }
    EMLog.d("db", "[perf]finished add test conversatoins. time spend(s):" + (System.currentTimeMillis() - l) / 1000L);
  }

  private static EMMessage createSentTextMsg(String paramString)
  {
    EMMessage localEMMessage = EMMessage.createSendMessage(EMMessage.Type.TXT);
    TextMessageBody localTextMessageBody = new TextMessageBody("send text msg " + System.currentTimeMillis());
    localEMMessage.addBody(localTextMessageBody);
    localEMMessage.setTo(paramString);
    localEMMessage.setMsgTime(getNextMsgTime());
    return localEMMessage;
  }

  private static EMMessage createReceivedTextMsg(String paramString)
  {
    EMMessage localEMMessage = EMMessage.createReceiveMessage(EMMessage.Type.TXT);
    TextMessageBody localTextMessageBody = new TextMessageBody("receive text msg " + System.currentTimeMillis());
    localEMMessage.addBody(localTextMessageBody);
    localEMMessage.setFrom(paramString);
    localEMMessage.setMsgTime(getNextMsgTime());
    return localEMMessage;
  }

  private static long getNextMsgTime()
  {
    long l;
    if (previousMsgTime == 0L)
      l = System.currentTimeMillis();
    else
      l = previousMsgTime + 10000L;
    previousMsgTime = l;
    return l;
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.easemob.chat.EMSDKLocalTest
 * JD-Core Version:    0.6.1
 */